<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
    <style>

       .log{
           width: 34px;
           height:28px;
           border: 1px solid #333;
           display: inline;
           margin: 10px;
           cursor: pointer;
       }
       .log:hover {
           background-color: #333;
        color: #fff;
       }

       .display {
        margin: 20px 0 ;
       }

       li {
            list-style: none;
            width: 100px;
            height: 130px;
            border: 2px solid lightgray;
            margin: 0 10px; 
            float: left;
       }
       img {
           position: absolute;
       }
       a {
            position: absolute;
            margin-left: 30px;
            margin-top: 90px;
       }
    </style>
</head>

<body>
    <div id="app">
        <app :logs="logs" :products="products"></app>
    </div>
</body>
<script>
    let product = {
        props: ['product'],
        template: "<div class='display'><li><img :src='product.img' width='100px'><br><a>{{product.name}}</a></li></div>"
    }

    let log = {
        // data: function () {
        //     return {cid:0}
        // },
        methods: {
            // catshow:function(){
            //     this.show= !this.show;
            // },
        },
        props: ['log'],
        template: "<div> {{log.name}}</div>",
        components: {
        }
    }

    let app = {
        methods: {
           choice:function(i) {
            this.cid = i;
           }
        },
        data: function () {
            return {cid:1}
        },
        props: ['logs', 'products'],
        template: "<div>"
            + "<log  class='log'  v-for='log in logs' :log='log' @click.native='choice(log.id)'></log>"
            + "<product v-for='product in products' :product='product' v-show='(cid==product.cid)'></product>"
            + "</div>",
        components:{
            log,
            product,
        }
    }

    new Vue({
        el: "#app",
        data: {
            logs: [
                {
                    name: '手机',
                    id: 1,
                },
                {
                    name: '配件',
                    id: 2,
                },
                // {
                //     name: '运营商',
                //     id: 3,
                // },
            ],
            products: [
                {
                    cid: 1,
                    name: '苹果',
                    img:'https://img13.360buyimg.com/n7/jfs/t1/113193/29/20766/35565/6227d13dE075d2e5f/dda8594cdee01aa8.jpg',
                },
                {
                    cid: 1,
                    name: '华为',
                    img:'https://img14.360buyimg.com/n7/jfs/t1/198531/37/20970/179596/62412c99E5496c3b9/d3283b556a61362a.jpg',
                },
                {
                    cid: 1,
                    name: 'vivo',
                    img:'https://img14.360buyimg.com/n7/jfs/t1/99911/23/28317/148231/6253d84fE053e6322/a184745e830e8a72.jpg',
                },
                {
                    cid: 2,
                    name: '充电器',
                    img: 'https://img13.360buyimg.com/n7/jfs/t1/138557/25/24317/267932/619d940aE80b82399/78319862c1ace8e5.jpg',
                },
                {
                    cid: 2,
                    name: '手机壳',
                    img: 'https://img13.360buyimg.com/n7/jfs/t1/131611/2/23179/318846/62457e57E0bc96b27/547f968fcbec81aa.jpg',
                },
                {
                    cid: 2,
                    name: '手机膜',
                    img: 'https://img14.360buyimg.com/n7/jfs/t1/197926/40/10751/272560/61541c7cE454f745d/8835ad348531cabb.jpg',
                },
            ],
        },
        components: {
            app,
        }
    })
</script>

</html>